/**
* @file test_cyril.c
*
*/
/*********************
*      INCLUDES
*********************/
#include "./test_cyril.h"

/*********************
*      DEFINES
*********************/

/**********************
*      TYPEDEFS
**********************/

/**********************
*  VARIABLES
**********************/

extern  lv_img_dsc_t bat_icon;
extern  lv_img_dsc_t rssi_icon;
extern  lv_img_dsc_t data_icon;
extern  lv_img_dsc_t map_icon;
extern  lv_img_dsc_t addr_icon;

gui_uwb_data_t gui_ud = {
    //默认参数
    .anchor_addr = {0xffff,0xffff,0xffff,0xffff},
    .anchor_sta = {0},
    .anchor_base_x = {0},
    .anchor_base_y = {0},
    .anchor_count = 0,
    .tag_dist = {0.2523,0.2345,0.5683,0},
};

gui_global_data_t gui_gd = {
    //默认参数
    .bat_val = 100,
    .tag_id = TAG_ID,
    .cur_page = NO_PAGE,
};

lv_obj_t* desktop;

char temp_buf[100];

/**********************
*  STATIC VARIABLES
**********************/

static uint8_t  res_scaler = LCD_RES_SCALER;

/* Top View Obj*/
static lv_obj_t* tv;
static lv_obj_t* tv_bat_icon;
static lv_obj_t* tv_bat_val;
static lv_obj_t* tv_rssi_icon;
static lv_obj_t* tv_rssi_val;
static lv_style_t tv_style;
static lv_style_t tv_rssi_val_style;
static lv_style_t tv_bat_val_style;
static lv_style_t tv_rssi_icon_style;
static lv_style_t tv_bat_icon_style;
static lv_obj_t* tv_return_btn;
static lv_style_t tv_return_btn_style;
static uint8_t tv_return_btn_sta;

/* Function Buttom Obj */
static lv_obj_t* fb_bg;
static lv_obj_t* fb_data;
static lv_obj_t* fb_data_icon;
static lv_obj_t* fb_map;
static lv_obj_t* fb_map_icon;
static lv_style_t fb_bg_style;
static lv_style_t fb_data_style;
static lv_style_t fb_map_style;
static lv_style_t fb_data_icon_style;
static lv_style_t fb_map_icon_style;
static uint8_t fb_data_sta;
static uint8_t fb_map_sta;

/* Data Page Obj */
static lv_obj_t* dp;
static lv_style_t page_style;
static lv_obj_t* dp_addr_icon;
static lv_style_t dp_addr_icon_style;
static lv_obj_t* dp_addr_icon_line;
static lv_style_t dp_line_style;
static lv_obj_t* dp_addr_val;
static lv_style_t dp_text_style;

/* Map Page Obj*/
static lv_obj_t* mp;
static lv_obj_t* mp_chart;
static lv_style_t mp_chart_style;
static lv_obj_t* mp_line[3];
static lv_style_t mp_line_style;
static lv_chart_series_t* mp_chart_ser;
static lv_obj_t* mp_angle_val;
static lv_obj_t* mp_uwb_sta_text;
static lv_style_t  mp_angle_val_style;
static lv_style_t  mp_uwb_sta_text_style;

/**********************
*  STATIC PROTO TYPES
**********************/
static void ComStyle_Init(void);
static void TopView_Create(void);
static void FuncBtn_Create(void);
static void DataPage_Create(void);
static void MapPage_Create(void);
static void Btn_EventCb(lv_event_t* e);
static float _abs(float input);

/**********************
*      MACROS
**********************/


/**********************
*   GLOBAL FUNCTIONS
**********************/
/*

//标签坐标
gui_ud.tag_x
gui_ud.tag_y

//磁力计角度
gui_gd.angle_val

//基站地址
gui_ud.anchor_addr[ANCHOR_1]
gui_ud.anchor_addr[ANCHOR_2]
gui_ud.anchor_addr[ANCHOR_3]

//各基站与标签的距离
gui_ud.tag_dist[ANCHOR_1]
gui_ud.tag_dist[ANCHOR_2]
gui_ud.tag_dist[ANCHOR_3]

//各基站的RSSI
gui_ud.anchor_rssi[ANCHOR_1]
gui_ud.anchor_rssi[ANCHOR_2]
gui_ud.anchor_rssi[ANCHOR_3]

//电池百分比
gui_gd.bat_val

//硬件标签ID
gui_gd.tag_id

//更新GUI
Gui_Update();

*/

void Test_Cyril_Init(void)
{
	
	  GUI_Init();
	
    Gui_UwbDataInit();

    ComStyle_Init();
    TopView_Create();
    FuncBtn_Create();
    MapPage_Create();
    DataPage_Create();

    Gui_SetTagID(DEFAULT);
    Gui_SetBatVal(gui_gd.bat_val);
	
		gui_ud.anchor_count = 0;
		Gui_UwbSetStaLabel();

    Gui_SetAnchorSta(ANCHOR_1, OFF);
    Gui_SetAnchorSta(ANCHOR_2, OFF);
    Gui_SetAnchorSta(ANCHOR_3, OFF);
		
		GUI_InitTask();
}


void Test_Cyril_Loop(void)
{
	while(1) {
	  
		gui_gd.bat_val=84;
    Gui_Update();
		
		GUI_Run();
		
		osDelay(1);
	}
}

void Gui_UwbDataInit(void)
{
    for (uint8_t i = 0; i < UWB_ANCHOR_NUM; i++)
    {
        gui_ud.anchor_base_x[i] = POS_NO_SET;
        gui_ud.anchor_base_y[i] = POS_NO_SET;
        gui_ud.tag_x = POS_NO_SET;
        gui_ud.tag_y = POS_NO_SET;
        gui_ud.anchor_addr[i] = 0xFFFF;
        gui_ud.anchor_sta[i] = 0;
    }
}

float axis_fa_x = 0.0;
float axis_fb_x = 0.0;
float axis_fa_y = 0.0;
float axis_fb_y = 0.0;
/*
*  B   *
*
*  A   C
*/
void Gui_UwbSetAnchorPos(float* input_x, float* input_y)
{
    float temp_x[3], temp_y[3];

    temp_x[ANCHOR_1] = *(input_x + ANCHOR_1);
    temp_x[ANCHOR_2] = *(input_x + ANCHOR_2);
    temp_x[ANCHOR_3] = *(input_x + ANCHOR_3);

    temp_y[ANCHOR_1] = *(input_y + ANCHOR_1);
    temp_y[ANCHOR_2] = *(input_y + ANCHOR_2);
    temp_y[ANCHOR_3] = *(input_y + ANCHOR_3);

    /* 坐标变换 */
    float min_x=0.0, max_x=0.0, min_y=0.0, max_y=0.0;

    min_x = temp_x[ANCHOR_1];
    min_y = temp_x[ANCHOR_1];
    for (uint8_t i = 0; i < 3; i++)
    {
        //找出最小的X
        if (temp_x[i] < min_x)
            min_x = temp_x[i];
        //找出最大的X
        if (temp_x[i] > max_x)
            max_x = temp_x[i];
        //找出最小的Y
        if (temp_y[i] < min_y)
            min_y = temp_y[i];
        //找出最大的Y
        if (temp_y[i] > max_y)
            max_y = temp_y[i];
    }
    axis_fa_x = (MP_CHART_WIDTH - POINT_BIAS - 5) / (max_x - min_x);
    axis_fb_x = MP_CHART_WIDTH - POINT_BIAS - axis_fa_x * max_x;

    axis_fa_y = (MP_CHART_HEIGHT - POINT_BIAS - 5) / (max_y - min_y);
    axis_fb_y = MP_CHART_HEIGHT - POINT_BIAS - axis_fa_y * max_y;

    gui_ud.anchor_base_x[ANCHOR_1] = temp_x[ANCHOR_1] * axis_fa_x + axis_fb_x;
    gui_ud.anchor_base_x[ANCHOR_2] = temp_x[ANCHOR_2] * axis_fa_x + axis_fb_x;
    gui_ud.anchor_base_x[ANCHOR_3] = temp_x[ANCHOR_3] * axis_fa_x + axis_fb_x;

    gui_ud.anchor_base_y[ANCHOR_1] = temp_y[ANCHOR_1] * axis_fa_y + axis_fb_y;
    gui_ud.anchor_base_y[ANCHOR_2] = temp_y[ANCHOR_2] * axis_fa_y + axis_fb_y;
    gui_ud.anchor_base_y[ANCHOR_3] = temp_y[ANCHOR_3] * axis_fa_y + axis_fb_y;

    //更新图表 不使用的话不会自动刷新
    lv_chart_refresh(mp_chart);
}

void Gui_UwbSetAnchorRssi(uint16_t* input_rssi)
{
    gui_ud.anchor_rssi[ANCHOR_1] = input_rssi[ANCHOR_1];
    gui_ud.anchor_rssi[ANCHOR_2] = input_rssi[ANCHOR_2];
    gui_ud.anchor_rssi[ANCHOR_3] = input_rssi[ANCHOR_3];

    if (gui_gd.cur_page != PAGE_DATA)
        return;

    lv_bar_set_value(gui_ud.anchor_rssi_bar[ANCHOR_1], gui_ud.anchor_rssi[ANCHOR_1], LV_ANIM_OFF);
    lv_bar_set_value(gui_ud.anchor_rssi_bar[ANCHOR_2], gui_ud.anchor_rssi[ANCHOR_2], LV_ANIM_OFF);
    lv_bar_set_value(gui_ud.anchor_rssi_bar[ANCHOR_3], gui_ud.anchor_rssi[ANCHOR_3], LV_ANIM_OFF);
}

void Gui_UwbSetTagPos(int16_t x, int16_t y, float angle)
{
    //需要设置坐标
    if (x != -1 || y != -1)
    {
        if (gui_gd.cur_page == PAGE_MAP)
            lv_obj_set_pos(gui_ud.tag_icon, x - POINT_BIAS, y - POINT_BIAS);
        gui_ud.tag_x = x;
        gui_ud.tag_y = y;
        lv_label_set_text_fmt(gui_ud.tag_pos_label, "(%d,%d)\n(%d,%d)", (int16_t)(gui_ud.tag_x * 1), (int16_t)(gui_ud.tag_y * 1), (int16_t)(locate.x_tag_final*100),(int16_t)(locate.y_tag_final*100));
    }
    if (angle != -1)
    {
        gui_gd.angle_val = angle;
        if (gui_gd.cur_page == PAGE_MAP) {
            lv_img_set_angle(gui_ud.tag_icon, gui_gd.angle_val * 10);
            lv_label_set_text_fmt(mp_angle_val, "Ang:%d", (int16_t)gui_gd.angle_val);
        }
    }
}

void Gui_UwbSetTagDist(float* tag_dist_val)
{
    gui_ud.tag_dist[ANCHOR_1] = tag_dist_val[ANCHOR_1];
    gui_ud.tag_dist[ANCHOR_2] = tag_dist_val[ANCHOR_2];
    gui_ud.tag_dist[ANCHOR_3] = tag_dist_val[ANCHOR_3];

    if (gui_gd.cur_page != PAGE_DATA)
        return;

    sprintf(temp_buf, "%.4fm", gui_ud.tag_dist[ANCHOR_1]);
    lv_label_set_text_fmt(gui_ud.tag_dist_label[ANCHOR_1], temp_buf);

    sprintf(temp_buf, "%.4fm", gui_ud.tag_dist[ANCHOR_2]);
    lv_label_set_text_fmt(gui_ud.tag_dist_label[ANCHOR_2], temp_buf);

    sprintf(temp_buf, "%.4fm", gui_ud.tag_dist[ANCHOR_3]);
    lv_label_set_text_fmt(gui_ud.tag_dist_label[ANCHOR_3], temp_buf);
}

void Gui_UwbSetStaLabel(void)
{
    if (gui_ud.anchor_count >= 3)
    {
        lv_label_set_text_fmt(mp_uwb_sta_text, "Online");
        lv_obj_align_to(mp_uwb_sta_text, mp_chart, LV_ALIGN_BOTTOM_RIGHT, -10, 18);
        lv_style_set_text_color(&mp_uwb_sta_text_style, lv_color_make(0, 255, 0));
    }
    else
    {
        lv_label_set_text_fmt(mp_uwb_sta_text, "Offline");
        lv_obj_align_to(mp_uwb_sta_text, mp_chart, LV_ALIGN_BOTTOM_RIGHT, -10, 18);
        lv_style_set_text_color(&mp_uwb_sta_text_style, lv_color_make(255, 0, 0));
    }

}
//设置电池百分比
void Gui_SetBatVal(uint8_t bat_val)
{
    gui_gd.bat_val = bat_val;
    lv_label_set_text_fmt(tv_bat_val, "%d%%", bat_val);
}
//设置TagID
void Gui_SetTagID(int16_t tag_id)
{
    if (tag_id != DEFAULT)
        gui_gd.tag_id = tag_id;
    lv_label_set_text_fmt(tv_rssi_val, "%d", gui_gd.tag_id);
}
//创建基站地址数据视图
void Gui_SetAddr(uint32_t anchor1_addr, uint32_t anchor2_addr, uint32_t anchor3_addr)
{
    gui_ud.anchor_addr[ANCHOR_1] = anchor1_addr;
    gui_ud.anchor_addr[ANCHOR_2] = anchor2_addr;
    gui_ud.anchor_addr[ANCHOR_3] = anchor3_addr;
    if (gui_gd.cur_page != PAGE_DATA)
        return;
    lv_label_set_text_fmt(dp_addr_val, "(1)0x%X (2)0x%X\n        (3)0x%X", anchor1_addr, anchor2_addr, anchor3_addr);
}
//设置标签LED的状态
void Gui_SetAnchorSta(uint8_t id, uint8_t on_off)
{
    switch (id)
    {
    case ANCHOR_1:
        if (on_off)
            gui_ud.anchor_sta[ANCHOR_1] = 1;
        else
            gui_ud.anchor_sta[ANCHOR_1] = 0;
        break;
    case ANCHOR_2:
        if (on_off)
            gui_ud.anchor_sta[ANCHOR_2] = 1;
        else
            gui_ud.anchor_sta[ANCHOR_2] = 0;
        break;
    case ANCHOR_3:
        if (on_off)
            gui_ud.anchor_sta[ANCHOR_3] = 1;
        else
            gui_ud.anchor_sta[ANCHOR_3] = 0;
        break;
    default:
        break;
    }

    if (gui_gd.cur_page != PAGE_DATA)
        return;

    switch (id)
    {
    case ANCHOR_1:
        if (on_off)
            lv_led_on(gui_ud.anchor_led[ANCHOR_1]);
        else
            lv_led_off(gui_ud.anchor_led[ANCHOR_1]);
        break;
    case ANCHOR_2:
        if (on_off)
            lv_led_on(gui_ud.anchor_led[ANCHOR_2]);
        else
            lv_led_off(gui_ud.anchor_led[ANCHOR_2]);
        break;
    case ANCHOR_3:
        if (on_off)
            lv_led_on(gui_ud.anchor_led[ANCHOR_3]);
        else
            lv_led_off(gui_ud.anchor_led[ANCHOR_3]);
        break;
    default:
        lv_led_off(gui_ud.anchor_led[ANCHOR_1]);
        lv_led_off(gui_ud.anchor_led[ANCHOR_2]);
        lv_led_off(gui_ud.anchor_led[ANCHOR_3]);
        break;
    }
}

void Gui_Update(void)
{
    static bool already_update = false;
    static gui_uwb_data_t gui_ud_last;
    static gui_global_data_t gui_gd_last;

    static float temp[3];
    static uint16_t temp_2[3];

    //已经在更新了
    if (already_update != false)
        return;
    already_update = true; //上锁

    if (gui_gd.angle_val != gui_gd_last.angle_val) Gui_UwbSetTagPos(DEFAULT, DEFAULT, gui_gd.angle_val);

    if (gui_gd.bat_val != gui_gd_last.bat_val) Gui_SetBatVal(gui_gd.bat_val);

    if (gui_gd.tag_id != gui_gd_last.tag_id) Gui_SetTagID(gui_gd.tag_id);

    if (gui_ud.anchor_addr[ANCHOR_1] != gui_ud_last.anchor_addr[ANCHOR_1] || \
        gui_ud.anchor_addr[ANCHOR_2] != gui_ud_last.anchor_addr[ANCHOR_2] || \
        gui_ud.anchor_addr[ANCHOR_3] != gui_ud_last.anchor_addr[ANCHOR_3] )
        Gui_SetAddr(gui_ud.anchor_addr[ANCHOR_1], gui_ud.anchor_addr[ANCHOR_2], gui_ud.anchor_addr[ANCHOR_3]);

    if (gui_ud.tag_dist[ANCHOR_1] != gui_ud_last.tag_dist[ANCHOR_1] || \
        gui_ud.tag_dist[ANCHOR_2] != gui_ud_last.tag_dist[ANCHOR_2] || \
        gui_ud.tag_dist[ANCHOR_3] != gui_ud_last.tag_dist[ANCHOR_3])
    {
        temp[ANCHOR_1] = gui_ud.tag_dist[ANCHOR_1];
        temp[ANCHOR_2] = gui_ud.tag_dist[ANCHOR_2];
        temp[ANCHOR_3] = gui_ud.tag_dist[ANCHOR_3];
        Gui_UwbSetTagDist(temp);
    }

    if (gui_ud.anchor_rssi[ANCHOR_1] != gui_ud_last.anchor_rssi[ANCHOR_1] || \
        gui_ud.anchor_rssi[ANCHOR_2] != gui_ud_last.anchor_rssi[ANCHOR_2] || \
        gui_ud.anchor_rssi[ANCHOR_3] != gui_ud_last.anchor_rssi[ANCHOR_3])
    {
        temp_2[ANCHOR_1] = gui_ud.anchor_rssi[ANCHOR_1];
        temp_2[ANCHOR_2] = gui_ud.anchor_rssi[ANCHOR_2];
        temp_2[ANCHOR_3] = gui_ud.anchor_rssi[ANCHOR_3];
        Gui_UwbSetAnchorRssi(temp_2);
    }

    if(gui_ud.tag_x != gui_ud_last.tag_x || gui_ud.tag_y != gui_ud_last.tag_y)
        Gui_UwbSetTagPos(gui_ud.tag_x, gui_ud.tag_y, DEFAULT);
        
    gui_gd_last.angle_val = gui_gd.angle_val;
    gui_gd_last.bat_val = gui_gd.bat_val;
    gui_gd_last.tag_id = gui_gd.tag_id;

    gui_ud_last.anchor_addr[ANCHOR_1] = gui_ud.anchor_addr[ANCHOR_1];
    gui_ud_last.anchor_addr[ANCHOR_2] = gui_ud.anchor_addr[ANCHOR_2];
    gui_ud_last.anchor_addr[ANCHOR_3] = gui_ud.anchor_addr[ANCHOR_3];

    gui_ud_last.tag_dist[ANCHOR_1] = gui_ud.tag_dist[ANCHOR_1];
    gui_ud_last.tag_dist[ANCHOR_2] = gui_ud.tag_dist[ANCHOR_2];
    gui_ud_last.tag_dist[ANCHOR_3] = gui_ud.tag_dist[ANCHOR_3];

    gui_ud_last.anchor_rssi[ANCHOR_1] = gui_ud.anchor_rssi[ANCHOR_1];
    gui_ud_last.anchor_rssi[ANCHOR_2] = gui_ud.anchor_rssi[ANCHOR_2];
    gui_ud_last.anchor_rssi[ANCHOR_3] = gui_ud.anchor_rssi[ANCHOR_3];

    gui_ud_last.tag_x = gui_ud.tag_x;
    gui_ud_last.tag_y = gui_ud.tag_y;

    already_update = false; //解锁
}


/**********************
*   STATIC FUNCTIONS
**********************/
//通用风格初始化
static void ComStyle_Init(void)
{
    if (page_style.sentinel != LV_STYLE_SENTINEL_VALUE)
    {
        lv_style_init(&page_style);
        lv_style_set_bg_color(&page_style, lv_color_make(50, 50, 50));
    }
    lv_style_set_radius(&page_style, 0);
    lv_style_set_border_width(&page_style, 0);
    lv_style_set_pad_all(&page_style, 4);
    lv_style_set_pad_top(&page_style, 5);
    lv_style_set_pad_left(&page_style, 5);
    lv_style_set_x(&page_style, -12);
    lv_style_set_y(&page_style, -13);
    lv_style_set_width(&page_style, LCD_HOR_RES);
    lv_style_set_height(&page_style, LCD_VER_RES * 0.9);
}

//顶层数据条创建
static void TopView_Create(void)
{

    /*set top_view_style*/
    lv_style_init(&tv_style);
    lv_style_set_radius(&tv_style, 2);
    lv_style_set_border_width(&tv_style, 0);
    lv_style_set_bg_color(&tv_style, lv_color_black());
    lv_style_set_align(&tv_style, LV_ALIGN_TOP_MID);
    lv_style_set_width(&tv_style, LCD_HOR_RES);
    lv_style_set_height(&tv_style, LCD_VER_RES * 0.1);
    lv_style_set_pad_all(&tv_style, 0);

    /*set top_view_battery_icon_style*/
    lv_style_init(&tv_bat_icon_style);
    lv_style_set_border_width(&tv_style, 0);
    lv_style_set_align(&tv_bat_icon_style, LV_ALIGN_LEFT_MID);
    //根据缩放系数调整图标尺寸 位置
    if (res_scaler == 1)
    {
        lv_style_set_transform_zoom(&tv_bat_icon_style, LV_IMG_ZOOM_NONE / 2.4);
        lv_style_set_x(&tv_bat_icon_style, LCD_HOR_RES * 0.7);
    }
    else {
        lv_style_set_transform_zoom(&tv_bat_icon_style, LV_IMG_ZOOM_NONE);
        lv_style_set_x(&tv_bat_icon_style, LCD_HOR_RES * 0.85);
    }

    /*set top_view_rssi_icon_style*/
    lv_style_init(&tv_rssi_icon_style);
    lv_style_set_align(&tv_rssi_icon_style, LV_ALIGN_LEFT_MID);
    //根据缩放系数调整图标尺寸 位置
    if (res_scaler == 1)
    {
        lv_style_set_transform_zoom(&tv_rssi_icon_style, LV_IMG_ZOOM_NONE / 2.4);
        lv_style_set_x(&tv_rssi_icon_style, -5);
    }
    else {
        lv_style_set_transform_zoom(&tv_rssi_icon_style, LV_IMG_ZOOM_NONE);
        lv_style_set_x(&tv_rssi_icon_style, LCD_HOR_RES * 0.02);
    }

    /*set top_view_battery_value_style*/
    lv_style_init(&tv_bat_val_style);
    lv_style_set_text_color(&tv_bat_val_style, lv_color_make(255, 255, 255));
    lv_style_set_align(&tv_bat_val_style, LV_ALIGN_RIGHT_MID);
    if (res_scaler == 1)
    {
        lv_style_set_text_font(&tv_bat_val_style, &lv_font_montserrat_8);
    }
    else
    {
        lv_style_set_text_font(&tv_bat_val_style, &lv_font_montserrat_24);
    }

    /*set top_view_rssi_value_style*/
    lv_style_init(&tv_rssi_val_style);
    lv_style_set_text_color(&tv_rssi_val_style, lv_color_make(255, 255, 255));
    lv_style_set_align(&tv_rssi_val_style, LV_ALIGN_LEFT_MID);
    if (res_scaler == 1)
    {
        lv_style_set_text_font(&tv_rssi_val_style, &lv_font_montserrat_8);
        lv_style_set_x(&tv_rssi_val_style, LCD_HOR_RES * 0.15);
    }
    else
    {
        lv_style_set_text_font(&tv_rssi_val_style, &lv_font_montserrat_24);
        lv_style_set_x(&tv_rssi_val_style, LCD_HOR_RES * 0.08);
    }

    //返回按键主题
    if (tv_return_btn_style.sentinel != LV_STYLE_SENTINEL_VALUE)
    {
        lv_style_init(&tv_return_btn_style);
        lv_style_set_radius(&tv_return_btn_style, 0);
        lv_style_set_bg_color(&tv_return_btn_style, lv_color_make(0, 0, 0));
    }

    /*create top_view*/
    tv = lv_obj_create(lv_scr_act());
    lv_obj_add_style(tv, &tv_style, 0);
    //禁止滚动
    lv_obj_clear_flag(tv, LV_OBJ_FLAG_SCROLLABLE);

    /*create top_view_battery_icon*/
    tv_bat_icon = lv_img_create(tv);
    lv_obj_add_style(tv_bat_icon, &tv_bat_icon_style, 0);
    lv_img_set_src(tv_bat_icon, &bat_icon);

    /*create top_view_battery_value*/
    tv_bat_val = lv_label_create(tv);
    lv_obj_add_style(tv_bat_val, &tv_bat_val_style, 0);
    lv_label_set_text_fmt(tv_bat_val, "%d%%", gui_gd.bat_val);

    /*create top_view_rssi_icon*/
    tv_rssi_icon = lv_img_create(tv);
    lv_obj_add_style(tv_rssi_icon, &tv_rssi_icon_style, 0);
    lv_img_set_src(tv_rssi_icon, &rssi_icon);

    /*create top_view_tag_id*/
    tv_rssi_val = lv_label_create(tv);
    lv_obj_add_style(tv_rssi_val, &tv_rssi_val_style, 0);
    lv_label_set_text_fmt(tv_rssi_val, "%d", gui_gd.tag_id);

    //初始化返回按钮
    tv_return_btn = lv_btn_create(tv);
    lv_obj_add_style(tv_return_btn, &tv_return_btn_style, 0);
    lv_obj_set_size(tv_return_btn, 40, 20);
    lv_obj_align(tv_return_btn, LV_ALIGN_BOTTOM_MID, 0, 0);
    lv_obj_move_foreground(tv_return_btn);
    tv_return_btn_sta = MAP_RETURN_PRESS;
    lv_obj_add_event_cb(tv_return_btn, Btn_EventCb, LV_EVENT_PRESSED, (void*)&tv_return_btn_sta);
}

//创建按键
static void FuncBtn_Create(void)
{
    /* style init*/

    /* set fb_bg_style*/
    if (fb_bg_style.sentinel != LV_STYLE_SENTINEL_VALUE)
    {
        lv_style_init(&fb_bg_style);
        lv_style_set_radius(&fb_bg_style, 0);
        lv_style_set_border_width(&fb_bg_style, 0);
        lv_style_set_x(&fb_bg_style, 0);
        lv_style_set_y(&fb_bg_style, LCD_VER_RES * 0.1);
        lv_style_set_width(&fb_bg_style, LCD_HOR_RES);
        lv_style_set_height(&fb_bg_style, LCD_VER_RES * 0.9);
        lv_style_set_bg_color(&fb_bg_style, lv_color_make(50, 50, 50));
    }

    /* set fb_data_style */
    if (fb_data_style.sentinel != LV_STYLE_SENTINEL_VALUE)
    {
        lv_style_init(&fb_data_style);
        lv_style_set_x(&fb_data_style, LCD_HOR_RES * 0.05);
        lv_style_set_y(&fb_data_style, LCD_VER_RES * 0.54);
        lv_style_set_size(&fb_data_style, LCD_HOR_RES * 0.25);
        lv_style_set_border_width(&fb_data_style, 0);
        lv_style_set_bg_color(&fb_data_style, lv_palette_main(LV_PALETTE_ORANGE));//lv_color_make(255, 185, 15));
    }

    /* set fb_map_style */
    if (fb_map_style.sentinel != LV_STYLE_SENTINEL_VALUE)
    {
        lv_style_init(&fb_map_style);
        lv_style_set_x(&fb_map_style, LCD_HOR_RES * 0.55);
        lv_style_set_y(&fb_map_style, LCD_VER_RES * 0.54);
        lv_style_set_size(&fb_map_style, LCD_HOR_RES * 0.25);
        lv_style_set_border_width(&fb_map_style, 0);
        lv_style_set_bg_color(&fb_map_style, lv_palette_main(LV_PALETTE_ORANGE));//lv_color_make(255, 185, 15));
    }

    /*set fb_data_icon_style*/
    if (fb_data_icon_style.sentinel != LV_STYLE_SENTINEL_VALUE)
    {
        lv_style_init(&fb_data_icon_style);
        lv_style_set_align(&fb_data_icon_style, LV_ALIGN_CENTER);
        //缩小2.4倍
        lv_style_set_transform_zoom(&fb_data_icon_style, LV_IMG_ZOOM_NONE / 2.4);
    }

    /*set fb_map_icon_style*/
    if (fb_map_icon_style.sentinel != LV_STYLE_SENTINEL_VALUE)
    {
        lv_style_init(&fb_map_icon_style);
        lv_style_set_align(&fb_map_icon_style, LV_ALIGN_CENTER);
        //根据缩放系数调整图标尺寸 位置
        //缩小2.4倍
        lv_style_set_transform_zoom(&fb_map_icon_style, LV_IMG_ZOOM_NONE / 2.4);
    }

    /* create function buttom background*/
    fb_bg = lv_obj_create(lv_scr_act());

    /* create desktop */
    desktop = fb_bg;

    lv_obj_add_style(fb_bg, &fb_bg_style, 0);
    lv_obj_clear_flag(fb_bg, LV_OBJ_FLAG_SCROLLABLE);

    /* create function_buttom_data */
    fb_data = lv_btn_create(fb_bg);
    lv_obj_add_style(fb_data, &fb_data_style, 0);
    lv_obj_move_foreground(fb_data);
    fb_data_sta = FB_DATA_PRESS;
    lv_obj_add_event_cb(fb_data, Btn_EventCb, LV_EVENT_PRESSED, (void*)&fb_data_sta);

    /* create function_buttom_map */
    fb_map = lv_btn_create(fb_bg);
    lv_obj_add_style(fb_map, &fb_map_style, 0);
    lv_obj_move_foreground(fb_map);
    fb_map_sta = FB_MAP_PRESS;
    lv_obj_add_event_cb(fb_map, Btn_EventCb, LV_EVENT_PRESSED, (void*)&fb_map_sta);

    /*create function_buttom_data_icon*/
    fb_data_icon = lv_img_create(fb_data);
    lv_obj_add_style(fb_data_icon, &fb_data_icon_style, 0);
    lv_img_set_src(fb_data_icon, &data_icon);
    lv_img_set_size_mode(fb_data_icon, LV_IMG_SIZE_MODE_REAL);

    /*create function_buttom_map_icon*/
    fb_map_icon = lv_img_create(fb_map);
    lv_obj_add_style(fb_map_icon, &fb_map_icon_style, 0);
    lv_img_set_src(fb_map_icon, &map_icon);
    lv_img_set_size_mode(fb_map_icon, LV_IMG_SIZE_MODE_REAL);
}

//创建数据界面
static void DataPage_Create(void)
{
    if (gui_gd.cur_page == PAGE_DATA)
        return;
    gui_gd.cur_page = PAGE_DATA;

    /* style init */
    if (dp_addr_icon_style.sentinel != LV_STYLE_SENTINEL_VALUE)
    {
        lv_style_init(&dp_addr_icon_style);
    }
    lv_style_set_align(&dp_addr_icon_style, LV_ALIGN_TOP_LEFT);
    lv_style_set_transform_zoom(&dp_addr_icon_style, LV_IMG_ZOOM_NONE);

    if (dp_line_style.sentinel != LV_STYLE_SENTINEL_VALUE)
    {
        lv_style_init(&dp_line_style);
        lv_style_set_radius(&dp_line_style, 0);
        lv_style_set_border_width(&dp_line_style, 0);
        lv_style_set_line_width(&dp_line_style, 4);
        lv_style_set_line_color(&dp_line_style, lv_palette_main(LV_PALETTE_ORANGE));
        lv_style_set_line_rounded(&dp_line_style, true);
    }

    if (dp_text_style.sentinel != LV_STYLE_SENTINEL_VALUE)
    {
        lv_style_init(&dp_text_style);
        lv_style_set_text_color(&dp_text_style, lv_color_make(255, 255, 255));
        lv_style_set_text_font(&dp_text_style, &lv_font_montserrat_8);
    }

    if (gui_ud.tag_dist_label_style.sentinel != LV_STYLE_SENTINEL_VALUE)
    {
        lv_style_init(&gui_ud.tag_dist_label_style);
        lv_style_set_bg_opa(&gui_ud.tag_dist_label_style, LV_OPA_COVER);
        lv_style_set_radius(&gui_ud.tag_dist_label_style, 3);
        lv_style_set_bg_color(&gui_ud.tag_dist_label_style, lv_palette_main(LV_PALETTE_ORANGE));
        lv_style_set_text_font(&gui_ud.tag_dist_label_style, &lv_font_montserrat_8);
        lv_style_set_align(&gui_ud.tag_dist_label_style, LV_ALIGN_CENTER);
        lv_style_set_text_color(&gui_ud.tag_dist_label_style,lv_color_make(255,255,255));
    }

    if (gui_ud.anchor_rssi_bar_style.sentinel != LV_STYLE_SENTINEL_VALUE)
    {
        lv_style_init(&gui_ud.anchor_rssi_bar_style);
        lv_style_set_bg_opa(&gui_ud.anchor_rssi_bar_style, LV_OPA_COVER);
        lv_style_set_bg_color(&gui_ud.anchor_rssi_bar_style, lv_palette_main(LV_PALETTE_GREY));
        lv_style_set_bg_grad_color(&gui_ud.anchor_rssi_bar_style, lv_palette_main(LV_PALETTE_RED));
        lv_style_set_bg_grad_dir(&gui_ud.anchor_rssi_bar_style, LV_GRAD_DIR_HOR);
    }

    /* obj init */
    if (dp != NULL)
        lv_obj_del(dp);
    dp = lv_obj_create(desktop);
    //禁止滚动
    lv_obj_clear_flag(dp, LV_OBJ_FLAG_SCROLLABLE);
    lv_obj_move_background(dp);
    lv_obj_add_style(dp, &page_style, 0);

    dp_addr_icon = lv_img_create(dp);
    lv_obj_add_style(dp_addr_icon, &dp_addr_icon_style, 0);
    lv_img_set_src(dp_addr_icon, &addr_icon);
    lv_obj_move_foreground(dp_addr_icon);

    static lv_point_t addr_icon_line_points[] = { {20, 0}, {20, 18} };
    dp_addr_icon_line = lv_line_create(dp);
    lv_line_set_points(dp_addr_icon_line, addr_icon_line_points, 2);
    lv_obj_add_style(dp_addr_icon_line, &dp_line_style, 0);
    lv_obj_move_foreground(dp_addr_icon_line);

    dp_addr_val = lv_label_create(dp);
    lv_label_set_text_fmt(dp_addr_val, "(1)0x%X (2)0x%X\n        (3)0x%X", \
        gui_ud.anchor_addr[ANCHOR_1], gui_ud.anchor_addr[ANCHOR_2], gui_ud.anchor_addr[ANCHOR_3]);
    lv_obj_add_style(dp_addr_val, &dp_text_style, 0);
    lv_obj_align_to(dp_addr_val, dp_addr_icon_line, LV_ALIGN_CENTER, 58, -3);
    lv_obj_move_foreground(dp_addr_val);

    //基站1 LED
    gui_ud.anchor_led[ANCHOR_1] = lv_led_create(dp);
    lv_obj_set_pos(gui_ud.anchor_led[ANCHOR_1], 115, 28);
    lv_obj_set_size(gui_ud.anchor_led[ANCHOR_1], 10, 10);
    lv_led_set_color(gui_ud.anchor_led[ANCHOR_1], lv_palette_main(LV_PALETTE_RED));
    Gui_SetAnchorSta(ANCHOR_1, OFF);

    //基站2 LED
    gui_ud.anchor_led[ANCHOR_2] = lv_led_create(dp);
    lv_obj_set_pos(gui_ud.anchor_led[ANCHOR_2], 115, 28 + 20);
    lv_led_set_color(gui_ud.anchor_led[ANCHOR_2], lv_palette_main(LV_PALETTE_GREEN));
    lv_obj_set_size(gui_ud.anchor_led[ANCHOR_2], 10, 10);
    Gui_SetAnchorSta(ANCHOR_2, OFF);

    //基站3 LED
    gui_ud.anchor_led[ANCHOR_3] = lv_led_create(dp);
    lv_obj_set_pos(gui_ud.anchor_led[ANCHOR_3], 115, 28 + 20 + 20);
    lv_led_set_color(gui_ud.anchor_led[ANCHOR_3], lv_palette_main(LV_PALETTE_BLUE));
    lv_obj_set_size(gui_ud.anchor_led[ANCHOR_3], 10, 10);
    Gui_SetAnchorSta(ANCHOR_3, OFF);

    //基站1 距离label
    gui_ud.tag_dist_label[ANCHOR_1] = lv_label_create(dp);
    sprintf(temp_buf, "%.4fm", gui_ud.tag_dist[ANCHOR_1]);
    lv_label_set_text_fmt(gui_ud.tag_dist_label[ANCHOR_1], temp_buf);
    lv_obj_add_style(gui_ud.tag_dist_label[ANCHOR_1], &gui_ud.tag_dist_label_style, 0);
    lv_obj_set_size(gui_ud.tag_dist_label[ANCHOR_1], 35, 10);
    lv_obj_align_to(gui_ud.tag_dist_label[ANCHOR_1], gui_ud.anchor_led[ANCHOR_1], LV_ALIGN_OUT_LEFT_MID, -10, 0);

    //基站2 距离label
    gui_ud.tag_dist_label[ANCHOR_2] = lv_label_create(dp);
    sprintf(temp_buf, "%.4fm", gui_ud.tag_dist[ANCHOR_2]);
    lv_label_set_text_fmt(gui_ud.tag_dist_label[ANCHOR_2], temp_buf);
    lv_obj_add_style(gui_ud.tag_dist_label[ANCHOR_2], &gui_ud.tag_dist_label_style, 0);
    lv_obj_set_size(gui_ud.tag_dist_label[ANCHOR_2], 35, 10);
    lv_obj_align_to(gui_ud.tag_dist_label[ANCHOR_2], gui_ud.anchor_led[ANCHOR_2], LV_ALIGN_OUT_LEFT_MID, -10, 0);

    //基站3 距离label
    gui_ud.tag_dist_label[ANCHOR_3] = lv_label_create(dp);
    sprintf(temp_buf, "%.4fm", gui_ud.tag_dist[ANCHOR_3]);
    lv_label_set_text_fmt(gui_ud.tag_dist_label[ANCHOR_3], temp_buf);
    lv_obj_add_style(gui_ud.tag_dist_label[ANCHOR_3], &gui_ud.tag_dist_label_style, 0);
    lv_obj_set_size(gui_ud.tag_dist_label[ANCHOR_3], 35, 10);
    lv_obj_align_to(gui_ud.tag_dist_label[ANCHOR_3], gui_ud.anchor_led[ANCHOR_3], LV_ALIGN_OUT_LEFT_MID, -10, 0);

    //基站1 rssi信号条
    gui_ud.anchor_rssi_bar[ANCHOR_1] = lv_bar_create(dp);
    lv_obj_add_style(gui_ud.anchor_rssi_bar[ANCHOR_1], &gui_ud.anchor_rssi_bar_style, LV_PART_INDICATOR);
    lv_obj_set_size(gui_ud.anchor_rssi_bar[ANCHOR_1], 60, 6);
    lv_obj_align_to(gui_ud.anchor_rssi_bar[ANCHOR_1], gui_ud.tag_dist_label[ANCHOR_1],LV_ALIGN_OUT_LEFT_MID,-5,0);
    lv_bar_set_range(gui_ud.anchor_rssi_bar[ANCHOR_1], 0, RSSI_MAX);
    lv_bar_set_value(gui_ud.anchor_rssi_bar[ANCHOR_1], RSSI_MAX*0.4, LV_ANIM_OFF);

    //基站2 rssi信号条
    gui_ud.anchor_rssi_bar[ANCHOR_2] = lv_bar_create(dp);
    lv_obj_add_style(gui_ud.anchor_rssi_bar[ANCHOR_2], &gui_ud.anchor_rssi_bar_style, LV_PART_INDICATOR);
    lv_obj_set_size(gui_ud.anchor_rssi_bar[ANCHOR_2], 60, 6);
    lv_obj_align_to(gui_ud.anchor_rssi_bar[ANCHOR_2], gui_ud.tag_dist_label[ANCHOR_2], LV_ALIGN_OUT_LEFT_MID, -5, 0);
    lv_bar_set_range(gui_ud.anchor_rssi_bar[ANCHOR_2], 0, RSSI_MAX);
    lv_bar_set_value(gui_ud.anchor_rssi_bar[ANCHOR_2], RSSI_MAX * 0.7, LV_ANIM_OFF);

    //基站3 rssi信号条
    gui_ud.anchor_rssi_bar[ANCHOR_3] = lv_bar_create(dp);
    lv_obj_add_style(gui_ud.anchor_rssi_bar[ANCHOR_3], &gui_ud.anchor_rssi_bar_style, LV_PART_INDICATOR);
    lv_obj_set_size(gui_ud.anchor_rssi_bar[ANCHOR_3], 60, 6);
    lv_obj_align_to(gui_ud.anchor_rssi_bar[ANCHOR_3], gui_ud.tag_dist_label[ANCHOR_3], LV_ALIGN_OUT_LEFT_MID, -5, 0);
    lv_bar_set_range(gui_ud.anchor_rssi_bar[ANCHOR_3], 0, RSSI_MAX);
    lv_bar_set_value(gui_ud.anchor_rssi_bar[ANCHOR_3], RSSI_MAX * 0.2, LV_ANIM_OFF);

    //移动UI到前台显示
    lv_obj_move_foreground(dp);
    lv_obj_move_foreground(fb_data);
    lv_obj_move_foreground(fb_map);
    lv_obj_add_style(dp, &page_style, 0);

    //设置当前页面ID为PAGE_DATA
    gui_gd.cur_page = PAGE_DATA;
}

//创建地图界面
static void MapPage_Create(void)
{
    if (gui_gd.cur_page == PAGE_MAP)
        return;
    gui_gd.cur_page = PAGE_MAP;

    if (mp_chart_style.sentinel != LV_STYLE_SENTINEL_VALUE)
    {
        lv_style_init(&mp_chart_style);
        //lv_style_set_bg_color(&mp_chart_style, lv_palette_lighten(LV_PALETTE_GREY, 3));
        lv_style_set_bg_color(&mp_chart_style, lv_color_make(158, 158, 158));
        lv_style_set_border_opa(&mp_chart_style, 1);
        lv_style_set_pad_all(&mp_chart_style, 1);
    }

    if (mp_line_style.sentinel != LV_STYLE_SENTINEL_VALUE)
    {
        lv_style_init(&mp_line_style);
        lv_style_set_border_opa(&mp_line_style, 1);
        lv_style_set_pad_all(&mp_line_style, 1);
    }

    if (mp_angle_val_style.sentinel != LV_STYLE_SENTINEL_VALUE)
    {
        lv_style_init(&mp_angle_val_style);
        lv_style_set_text_font(&mp_angle_val_style, &lv_font_montserrat_14);
        lv_style_set_text_color(&mp_angle_val_style, lv_color_make(255, 255, 255));
    }

    if (mp_uwb_sta_text_style.sentinel != LV_STYLE_SENTINEL_VALUE)
    {
        lv_style_init(&mp_uwb_sta_text_style);
        lv_style_set_text_font(&mp_uwb_sta_text_style, &lv_font_montserrat_14);
        lv_style_set_text_color(&mp_uwb_sta_text_style, lv_color_make(255, 255, 255));
    }
		
    if (gui_ud.tag_pos_label_style.sentinel != LV_STYLE_SENTINEL_VALUE)
    {
        lv_style_init(&gui_ud.tag_pos_label_style);
        lv_style_set_text_font(&gui_ud.tag_pos_label_style, &lv_font_montserrat_14);
        lv_style_set_text_color(&gui_ud.tag_pos_label_style, lv_color_make(255, 255, 255));
        lv_style_set_text_decor(&gui_ud.tag_pos_label_style, LV_TEXT_DECOR_UNDERLINE);
    }

    //初始化页面画布
    if (mp != NULL)
        lv_obj_del(mp);
    mp = lv_obj_create(desktop);
    lv_obj_add_style(mp, &page_style, 0);
    lv_obj_clear_flag(mp, LV_OBJ_FLAG_SCROLLABLE);

    //初始化图表
    mp_chart = lv_chart_create(mp);
    lv_obj_clear_flag(mp_chart, LV_OBJ_FLAG_SCROLLABLE);
    //obj 状态设置
    //lv_obj_clear_flag(mp_chart, LV_OBJ_FLAG_SCROLL_ELASTIC);
    //lv_obj_add_state(mp_chart, LV_STATE_HOVERED);
    //lv_obj_add_flag(mp_chart, LV_OBJ_FLAG_CLICK_FOCUSABLE);
    //图表坐标位置&风格初始化
    lv_obj_set_size(mp_chart, MP_CHART_WIDTH, MP_CHART_HEIGHT);
    lv_obj_align(mp_chart, LV_ALIGN_CENTER, 8, -8);
    lv_obj_add_style(mp_chart, &mp_chart_style, 0);
    lv_obj_set_style_line_width(mp_chart, 0, LV_PART_ITEMS);   /*Remove the lines*/
    //lv_chart_set_div_line_count(mp_chart, 0, 0);
    lv_obj_set_style_line_color(mp_chart, lv_color_make(211, 211, 211), 0);
    //设置图表类型为散点图
    lv_chart_set_type(mp_chart, LV_CHART_TYPE_SCATTER);
    //设置图表坐标范围
    lv_chart_set_range(mp_chart, LV_CHART_AXIS_PRIMARY_X, 0, 128);
    lv_chart_set_range(mp_chart, LV_CHART_AXIS_PRIMARY_Y, 0, 130);
    //设置散点数量
    lv_chart_set_point_count(mp_chart, 30);
    //设置连续点集
    mp_chart_ser = lv_chart_add_series(mp_chart, lv_palette_main(LV_PALETTE_RED), LV_CHART_AXIS_PRIMARY_Y);
#if 1
    //设置点坐标
    lv_chart_set_next_value2(mp_chart, mp_chart_ser, (uint16_t)gui_ud.anchor_base_x[ANCHOR_1], (uint16_t)gui_ud.anchor_base_y[ANCHOR_1]);
    lv_chart_set_next_value2(mp_chart, mp_chart_ser, (uint16_t)gui_ud.anchor_base_x[ANCHOR_2], (uint16_t)gui_ud.anchor_base_y[ANCHOR_2]);
    lv_chart_set_next_value2(mp_chart, mp_chart_ser, (uint16_t)gui_ud.anchor_base_x[ANCHOR_3], (uint16_t)gui_ud.anchor_base_y[ANCHOR_3]);
    //修改点坐标
 //   lv_chart_set_value_by_id2(mp_chart, mp_chart_ser, 0, 0, 0);
 //   lv_chart_set_value_by_id2(mp_chart, mp_chart_ser, 1, 100, 100);
#endif

    //标签坐标图标
    gui_ud.tag_icon = lv_img_create(mp_chart);
    lv_obj_add_style(gui_ud.tag_icon, &dp_addr_icon_style, 0);
    lv_img_set_src(gui_ud.tag_icon, &addr_icon);
    lv_img_set_angle(gui_ud.tag_icon, 1800 + 600);
    //lv_obj_center(gui_ud.tag_icon);
    lv_obj_set_pos(gui_ud.tag_icon, MP_CHART_WIDTH / 2 - POINT_BIAS, MP_CHART_HEIGHT / 2 - POINT_BIAS);
    lv_obj_move_foreground(gui_ud.tag_icon);

    //设置角度label
    mp_angle_val = lv_label_create(mp);
    lv_obj_add_style(mp_angle_val, &mp_angle_val_style,0);
    lv_label_set_text_fmt(mp_angle_val, "Ang:%d", (int16_t)gui_gd.angle_val);
    lv_obj_align_to(mp_angle_val, mp_chart, LV_ALIGN_BOTTOM_LEFT, 0, 18 );
    

    //状态lael
    mp_uwb_sta_text = lv_label_create(mp);
    lv_obj_add_style(mp_uwb_sta_text, &mp_uwb_sta_text_style, 0);
    lv_obj_align_to(mp_uwb_sta_text, mp_chart, LV_ALIGN_BOTTOM_RIGHT, -10, 18);
    Gui_UwbSetStaLabel();
		
		//标签坐标label
    gui_ud.tag_pos_label = lv_label_create(mp_chart);
    lv_obj_align(gui_ud.tag_pos_label, LV_ALIGN_TOP_MID, 0, 5);
    lv_obj_add_style(gui_ud.tag_pos_label, &gui_ud.tag_pos_label_style, 0);
    lv_label_set_text_fmt(gui_ud.tag_pos_label, "(%d,%d)",(int16_t)(gui_ud.tag_x*100),(int16_t)(gui_ud.tag_y*100));

    //移动UI到前台显示
    lv_obj_move_foreground(mp);
    lv_obj_add_style(mp, &page_style, 0);
    //设置当前页面ID为PAGE_MAP
    gui_gd.cur_page = PAGE_MAP;
}

//按键callback
static void Btn_EventCb(lv_event_t* e)
{
    lv_event_code_t code = lv_event_get_code(e);
    uint8_t* user_data = (uint8_t*)lv_event_get_user_data(e);
    //翻转LED
    //HAL_GPIO_TogglePin(DEBUG_LED_GPIO_Port, DEBUG_LED_Pin);
    switch (code)
    {
    case LV_EVENT_PRESSED:
        //printf("press! user_data:%d\r\n",user_data);
        switch (*user_data)
        {
        case FB_DATA_PRESS:
            //printf("data press!\r\n");
            if (page_style.sentinel != LV_STYLE_SENTINEL_VALUE)
            {
                lv_style_init(&page_style);
            }
            lv_style_set_bg_color(&page_style, lv_color_make(50, 50, 50));
            DataPage_Create();
            break;
        case FB_MAP_PRESS:
            //printf("map press!\r\n");
            if (page_style.sentinel != LV_STYLE_SENTINEL_VALUE)
            {
                lv_style_init(&page_style);
            }
            lv_style_set_bg_color(&page_style, lv_color_make(50, 50, 50));
            MapPage_Create();
            break;
        case MAP_RETURN_PRESS:
            //printf("MAP_RETURN_PRESS\r\n");
            if (page_style.sentinel != LV_STYLE_SENTINEL_VALUE)
            {
                lv_style_init(&page_style);
            }
            lv_style_set_bg_color(&page_style, lv_color_make(50, 50, 50));
            DataPage_Create();
            break;
        }
        break;
    case LV_EVENT_LONG_PRESSED:
        //printf("long press\r\n");
        break;
    default:
        break;
    }
}

static float _abs(float input)
{
    return (input < 0 ? -1 * input : input);
}


